package com.wuxiaofan.order.client;

import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class Idgenerator {

    @Value("${tinyid.bizType}")
    private String bizType;
    @Value("${tinyid.batchSize}")
    private Integer batchSize;
    @Value("${tinyid.token}")
    private String token;
    @Resource
    private TinyIdClient tinyIdClient;

    public long getId(){
        String id = "";
        try{
            id = tinyIdClient.nextIdSimple(bizType,batchSize,token);
        }catch (Exception e){
            log.error("获取主键异常,重试:{}",e);
            try{
                Thread.sleep(100);
            }catch (Exception e1){
            }
            return getId();
        }
        return Long.parseLong(id);
    }
}
